import request from '@/utils/request'

//后台统一--请求地址前缀
let urlPrefix = "/sys/user";
// 用户登录
export function login(data) {
  return request({
    url: urlPrefix + '/login',
    method: 'post',
    data
  })
}

// 获取用户信息
export function getInfo(token) {
  return request({
    url: urlPrefix + '/info',
    method: 'get',
    params: { token }
  })
}

// 退出登录
export function logout() {
  return request({
    url: urlPrefix + '/logout',
    method: 'post'
  })
}

// 分页查询用户列表信息
export function getUserList(searchModel){
  return request({
    url: urlPrefix + '/list',
    method: 'get',
    params:{
      pageNo: searchModel.pageNo,
      pageSize: searchModel.pageSize,
      username: searchModel.username,
      phone: searchModel.phone
    }
  });
}

// 添加用户
export function addUser(user){
  return request({
    url: urlPrefix + '',
    method: 'post',
    data: user
  });
}

//修改用户
export function updateUser(user){
  return request({
    url: urlPrefix + '',
    method: 'put',
    data: user
  });
}

//保存用户
export function saveUser(user){
  if(user.id == null && user.id == undefined){
    return addUser(user);
  }
  return updateUser(user);
}

//获取用户信息
export function getUserById(id){
  return request({
    //url: '/user/' + id,
    url: urlPrefix + `/${id}`,
    method: 'get'
  });
}

//删除用户
export function deleteUserById(id){
  return request({
    url: urlPrefix + `/${id}`,
    method: 'delete'
  });
}

// 修改用户状态
export function updateUserStatus(user){
  return request({
    url: urlPrefix + `/updateStatus`,
    method: 'post',
    data: user
  });
}



//查询在线用户
export function getOnlineUserList(searchModel){
  return request({
    url: urlPrefix + '/online/list',
    method: 'get',
    params:{
      pageNo: searchModel.pageNo,
      pageSize: searchModel.pageSize,
    }
  });
}


//获取用户信息
export function getOnlineUserById(id){
  return request({
    url: urlPrefix + `/online/${id}`,
    method: 'get'
  });
}


export function onlineLogout(token){
  return request({
    url: urlPrefix + `/online/logout/${token}`,
    method: 'get'
  });
}


